<?php
class Employee_model extends ci_model{



/*function list_staff($limit, $offset, $sort_by, $sort_order)
{

	 $q = $this->db->get('EMPLOYEE');
      
	  		  if ($q->num_rows()>0)
			  {	
			  foreach ($q->result()as $row )
			  {
			  $data[]=$row;
			  }
			  }
			
		return $data;
	

	
	
	
	}
*/	

function list_employees($limit, $offset, $sort_by, $sort_order, $table)
{
	
	
	 
			$sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
			$sort_columns = array('employeeID','title', 'firstName', 'lastName', 'city', 'position',);	
			$sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'title';
	
		// results query
			$q = $this->db->select('employeeID,title, firstName, lastName, ')
				->from($table)
				->limit($limit, $offset)
				->order_by($sort_by, $sort_order);
			
			 $ret['rows'] = $q->get()->result();

		// count query
		
			$q = $this->db->select('COUNT(*) as count', FALSE)
				->from($table);
			$tmp = $q->get()->result();
			$ret['num_rows'] = $tmp[0]->count;
			return $ret;
		
	
}


		



















function add_employee(){

							$data=array(
											
											'firstName'=>$this->input->post('firstName'),
											'lastName'=>$this->input->post('lastName'),
											'middleName'=>$this->input->post('middleName'),
											'workNumber'=>$this->input->post('workNumber'),
											'mobileNumber'=>$this->input->post('mobileNumber'),
											'homeNumber'=>$this->input->post('homeNumber'),
											'email'=>$this->input->post('email'),
											'sex'=>$this->input->post('sex'),
											'dob'=>$this->input->post('dob'),
											'firstLineAddress'=>$this->input->post('firstLineAddress'),
											'secondLineAddress'=>$this->input->post('secondLineAddress'),
											'postcode'=>$this->input->post('postcode'),
											'dob'=>$this->input->post('dob'),
											'city'=>$this->input->post('city'),
											'country'=>$this->input->post('dob'),
											'position'=>$this->input->post('position'),
											'imageURL'=>$this->input->post('imageURL'),
											'nin'=>$this->input->post('nin'),
											'maritalstatus'=>$this->input->post('maritalstatus')
											
											);
							
							$insert =$this->db->insert('EMPLOYEE',$data);
							return $insert;
}




function delete_employee()
{
	
							$this->db->where('employeeID', $this->uri->segment(3));
							$this->db->delete('EMPLOYEE');
						
	                         
	
	}


function get_employee()
{
	
						//	$this->db->where('employeeID', 92);
							//$employee=$this->db->get('EMPLOYEE');
							//return $employee;
	                      //   print_r($employee);
							// echo"hello";
	
	
				$q = $this->db->select('*')
				->from('EMPLOYEE')
				->where('employeeID', $this->uri->segment(3));
				 $ret = $q->get()->row_array();
				return  $ret; 	
				
				
	
	
	}







function update_employee ()
				{
					
					$data=array(
											
											'firstName'=>$this->input->post('firstName'),
											'lastName'=>$this->input->post('lastName'),
											'middleName'=>$this->input->post('middleName'),
											'workNumber'=>$this->input->post('workNumber'),
											'mobileNumber'=>$this->input->post('mobileNumber'),
											'homeNumber'=>$this->input->post('homeNumber'),
											'email'=>$this->input->post('email'),
											'sex'=>$this->input->post('sex'),
											'dob'=>$this->input->post('dob'),
											'firstLineAddress'=>$this->input->post('firstLineAddress'),
											'secondLineAddress'=>$this->input->post('secondLineAddress'),
											'postcode'=>$this->input->post('postcode'),
											'dob'=>$this->input->post('dob'),
											'city'=>$this->input->post('city'),
											'country'=>$this->input->post('dob'),
											'position'=>$this->input->post('position'),
											'imageURL'=>$this->input->post('imageURL'),
											'nin'=>$this->input->post('nin'),
											'maritalstatus'=>$this->input->post('maritalstatus')
											
											);
					
					
				
					
				
					$this->db->where('employeeID',$this->uri->segment(3));
					$this->db->update('EMPLOYEE' , $data);
				}
}
	
?>